﻿#coding=utf-8
#from heroes import *

import sys
import os

class UiBase:
    """description of class"""

    def select(self, int_range, tips, err_tips):
        pass

    def select_correct(self, int_range, tips, err_tips):
        pass

    def show_list(self, item_list, tips):
        pass
    
    def show_list_except(self, item_list, except_range, tips):
        pass

    def output(self, text):
        pass

    def clear(self):
        pass

class ConsoleUi(UiBase):

    def select(self, int_range, tips, err_tips):
        sel = int(input(tips))
        
        if not sel in int_range:
            sys.stdout.write("%s\n" % err_tips)
            return None
        return sel

    def select_correct(self, int_range, tips, err_tips):
        sel = int(input(tips))
        while not sel in int_range:
            sys.stdout.write("%s\n" % err_tips)
            sel = int(input(tips))
            
        return sel

    def show_list(self, item_list, tips):
        sys.stdout.write(tips)
        #print([u"%d.%s" % (i, list[i]) for i in range(0, len(list))])
        for i in range(0, len(item_list)):
            sys.stdout.write("%d.%s " % (i, item_list[i]))
        sys.stdout.write("\n")
        
    def show_list_except(self, item_list, except_range, tips):
        sys.stdout.write(tips)
        #print([u"%d.%s" % (i, list[i]) for i in range(0, len(list))])
        list_left = []
        for i in item_list:
            if not i in except_range:
                list_left.append(i)
        
        for i in range(0, len(list_left)):
            sys.stdout.write("%d.%s " % (i, list_left[i]))
        sys.stdout.write("\n")

    def output(self, text):
        pass

    def clear(self):
        pass

    def pause(self):
        pass


class CmdConsoleUi(ConsoleUi):

    def output(self, text):
        sys.stdout.write(text)

    def clear(self):
        os.system("cls")

    def pause(self):
        os.system("pause")



